using System;
using System.Xml.Serialization;

namespace SBPweb.Forge.Common.Versioning
{
	/// <summary>
	/// Serializable version class
	/// </summary>
	public class SerializableVersion : IComparable
	{

		#region Private members

		private System.Version systemVersion;

		#endregion

		#region Constructor logic

		/// <summary>
		/// Serializable version
		/// </summary>
		public SerializableVersion()
		{
			systemVersion = new System.Version("0.0.0.0");
		}

		/// <summary>
		/// Serializable version
		/// </summary>
		/// <param name="version">version</param>
		public SerializableVersion(System.Version version)
		{
			systemVersion = version;
		}

		/// <summary>
		/// Serializable version
		/// </summary>
		/// <param name="version">version string</param>
		public SerializableVersion(string version)
		{
			systemVersion = new System.Version(version);
		}

		/// <summary>
		/// Serializable version
		/// </summary>
		/// <param name="major">major number</param>
		/// <param name="minor">minor number</param>
		public SerializableVersion(int major, int minor)
		{
			systemVersion = new System.Version(major, minor);
		}

		/// <summary>
		/// Serializable version
		/// </summary>
		/// <param name="major">major number</param>
		/// <param name="minor">minor number</param>
		/// <param name="build">build number</param>
		public SerializableVersion(int major, int minor, int build)
		{
			systemVersion = new System.Version(major, minor, build);
		}

		/// <summary>
		/// Serializable version
		/// </summary>
		/// <param name="major">major number</param>
		/// <param name="minor">minor number</param>
		/// <param name="build">build number</param>
		/// <param name="revision">revision number</param>
		public SerializableVersion(int major, int minor, int build, int revision)
		{
			systemVersion = new System.Version(major, minor, build, revision);
		}

		#endregion

		#region Public members

		/// <summary>
		/// System version
		/// </summary>
		[XmlIgnore()]
#if !SILVERLIGHT
		[SoapIgnore()]
#endif
        public System.Version SystemVersion
		{
			get { return systemVersion; }
			set { systemVersion = value; }
		}

		/// <summary>
		/// Get the major number
		/// </summary>
		public int Major
		{
			get
			{
				return systemVersion.Major;
			}
			set
			{
                ;
			}
		}

		/// <summary>
		/// Get the minor number
		/// </summary>
        public int Minor
		{
			get 
			{
				return systemVersion.Minor;
			}
			set
			{
                ;
			}
		}

		/// <summary>
		/// Get the revision number
		/// </summary>
		public int Revision 
		{
			get
			{
				return systemVersion.Revision;
			}
			set
			{
                ;
			}
		}

		/// <summary>
		/// Get the build number
		/// </summary>
		public int Build
		{
			get
			{
				return systemVersion.Build;
			}
			set
			{
                ;
			}
		}

		/// <summary>
		/// Get as string
		/// </summary>
        public string AsString
        {
            get
            {
                return this.ToString();
            }
            set
            {
                ;
            }
        }

		/// <summary>
		/// ToString method
		/// </summary>
		/// <returns>string</returns>
		public override string ToString()
		{
			return systemVersion.ToString();
		}


		#endregion

		#region IComparable Members

		/// <summary>
		/// Compare method
		/// </summary>
		/// <param name="obj">compare to</param>
		/// <returns>result</returns>
		public int CompareTo(object obj)
		{
			if (obj != null)
			{
				return this.SystemVersion.CompareTo((obj as SerializableVersion).SystemVersion);
			}
			return 1;
		}

		#endregion

	}
}
